var _ = require('lodash');
var goods = [];
function carts(state = goods, action) {
  switch (action.type) {
    case 'ADDGOODS':
      var pos = _.findIndex(state, { id: action.payload.id });
      if (pos !== -1) {
        state[pos].quantity = state[pos].quantity + 1;
        state[pos].subTotal = state[pos].quantity * state[pos].price.number;
        console.log(1);
        return [...state];
      } else {
        action.payload.quantity = 1;
        action.payload.subTotal = action.payload.price.number;
        console.log(2);
        return [...state, action.payload];
      }
    default:
      return state;
  }
}
export default carts;
